package top.mcwebsite.playandroid.business.settings.impl.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Divider
import androidx.compose.material3.DividerDefaults
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import top.mcwebsite.playandroid.common.uiWidget.CustomDialog
import top.mcwebsite.playandroid.strings.Str

@Composable
fun LogoutDialog(
    isShow: Boolean,
    confirm: () -> Unit,
    cancel: () -> Unit,
) {
    if (!isShow) {
        return
    }
    CustomDialog(
        onDismissRequest = {
            cancel()
        }
    ) {
        Column(
            modifier = Modifier
                .width(IntrinsicSize.Min)
                .background(shape = RoundedCornerShape(25.dp), color = MaterialTheme.colorScheme.surface)
        ) {
            Box(
                modifier = Modifier
                    .width(300.dp)
                    .height(100.dp),
                contentAlignment = Alignment.Center
            ) {
                Text(text = stringResource(id = Str.logout_confirm))
            }
            Divider(modifier = Modifier.fillMaxWidth())
            Row(
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier
                    .height(50.dp)
                    .fillMaxWidth(),
            ) {
                Box(
                    contentAlignment = Alignment.Center,
                    modifier = Modifier
                        .fillMaxHeight()
                        .weight(1f)
                        .clickable {
                            cancel()
                        }
                ) {
                    Text(
                        text = stringResource(id = Str.cancel),
                        color = LocalContentColor.current.copy(alpha = 0.7f),
                    )
                }
                Box(
                    modifier = Modifier
                        .fillMaxHeight()
                        .width(0.5.dp)
                        .background(color = DividerDefaults.color)
                )
                Box(
                    contentAlignment = Alignment.Center,
                    modifier = Modifier
                        .fillMaxHeight()
                        .weight(1f)
                        .clickable {
                            confirm()
                        }
                ) {
                    Text(
                        text = stringResource(id = Str.confirm),
                        color = MaterialTheme.colorScheme.primary,
                    )
                }
            }
        }
    }
}

